package pub.guoxin.oops.tidy;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by yangjt on 2017-01-06.
 */
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
    private final static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String date = p.readValueAs(String.class);
        return LocalDateTime.parse(date, dateTimeFormatter);
    }
}
